<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/30
 * Time: 10:14
 */

namespace Home\Controller;
use Think\Controller;
class AllmsgController extends Controller{
    public function index(){
        $uname=I('uname');
        $cnumber=I('cnumber');
        $news=M();
        $sql1="select distinct  tp_user.uname,tp_user.cnumber,tp_user.idcard,tp_user.uphone,(select SUM(money) FROM tp_cost where tp_user.uname='$uname' AND tp_user.cnumber='$cnumber') as money,(select SUM(ctime) FROM tp_cost where tp_user.uname='$uname' AND tp_user.cnumber='$cnumber') as ctime,(select SUM(paymoney) FROM tp_cost where tp_user.uname='$uname' AND tp_user.cnumber='$cnumber') as paymoney  FROM tp_user JOIN tp_cost on tp_user.uid=tp_cost.uid where tp_user.uname='$uname' AND tp_user.cnumber='$cnumber'";

        $sql="select uname,cnumber,idcard,uphone,money,intime,ctime FROM tp_user JOIN tp_cost where tp_user.uid=tp_cost.uid AND tp_user.uname='$uname' AND cnumber='$cnumber'";
        $alldata=$news->query($sql);
        $data=$news->query($sql1);
//            echo $news->getLastSql();
//            var_dump($data);
        foreach ($alldata as $sk){
            $intime=$sk['intime'];
        }
        foreach ($data as $sk){
            $monry=$sk['money'];
            $paymoney=$sk['paymoney'];

        }
        $nopaymoney=$monry-$paymoney;
        $this->assign("nopaymoney",$nopaymoney);
        $intime=date('Y-m-d H:i:s',$intime);
        $this->assign("intime",$intime);
        $this->assign("alldata",$alldata);
        $this->assign("data",$data);
        $this->display();
    }
    public function back(){
        if(session('username')){
            redirect(U('/Home/Usermsg/index/'),0,'返回');
        }else {
            redirect(U('/Home/Login/index/'), 0, '重新登录');
        }
    }
}